﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Model;
using Common;

namespace Controller
{
   public  class ServerConnectBO
    {

        private ServerConnectDAO _scDAO;
        public ServerConnectDAO ScDAO
        {
            get
            {
                if (_scDAO == null)
                    _scDAO = FactoryModelDAO.CurrentFA.CreateServerConnectDAOInstance();
                return _scDAO; 
            }
        }

        /// <summary>
        /// 获取局域网中所有SQL Server实例
        /// </summary>
        /// <returns></returns>
       public List<string> GetSqlServerOverLan()
        {
            try
            {
                return ScDAO.GetSqlServerOverLan();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

       /// <summary>
       /// 通过实例名获取数据库列表
       /// </summary>
       /// <param name="serverName">实例名</param>
       /// <param name="username">SQL用户名（登录方式为Win时可以传空值）</param>
       /// <param name="password">SQL密码（登录方式为Win时可以传空值）</param>
       /// <param name="verifyMode">登陆方式（WIN和SQL）</param>
       /// <returns></returns>
       public List<string> GetDatabaseNameFromServer(string serverName, string username, string password, enumVerifyMode verifyMode)
       {
           try
           {
               return ScDAO.GetDatabaseNameFromServer(serverName, username, password, verifyMode);
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }

       /// <summary>
       /// 通过数据库名获取所有数据表
       /// </summary>
       /// <param name="serverName">实例名</param>
       /// <param name="dbName">数据库名</param>
       /// <param name="username">SQL用户名（登录方式为Win时可以传空值）</param>
       /// <param name="password">SQL密码（登录方式为Win时可以传空值）</param>
       /// <param name="verifyMode">登陆方式（WIN和SQL）</param>
       /// <returns></returns>
       public List<string> GetTablesFromDataBase(string serverName, string dbName, string username, string password, enumVerifyMode verifyMode)
       {
           try
           {
               return ScDAO.GetTablesFromDataBase(serverName, dbName, username, password, verifyMode);
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }

       /// <summary>
       /// 通过数据库名获取所有数据表
       /// </summary>
       /// <param name="conStr">连接字符串</param>
       /// <returns></returns>
       public List<string> GetTablesFromDataBase(string conStr)
       {
           try
           {
               return ScDAO.GetTablesFromDataBase(conStr);
           }
           catch (Exception ex)
           {
               throw ex;
           }
       }
   
       /// <summary>
        /// 获取正确的连接字符串
        /// </summary>
       /// <param name="serverName">实例名</param>
       /// <param name="username">SQL用户名（登录方式为Win时可以传空值）</param>
       /// <param name="password">SQL密码（登录方式为Win时可以传空值）</param>
       /// <param name="verifyMode">登陆方式（WIN和SQL）</param>
        /// <returns></returns>
        public string GetConnectString(string serverName,string dbName, string username,string password, enumVerifyMode verifyMode)
       {
           return ScDAO.GetConnectString(serverName, dbName, username, password, verifyMode);
       }
   }
}
